<template>
  <div class="exhibit-top" :style="{ minHeight: getScrollHeight }">
    <div class="ex-img">
      <!-- 展示图片 -->
      <img
        class="cover"
        v-if="props.info.images?.length > 1"
        :src="$filters.getLinkUrl(props.info.images[current]?.data + '?imageView2/3/w/1000/format/webp')"
        alt=""
        @click="viewImg(props.info.images[current]?.data)"
      />
      <img
        class="cover"
        v-else
        :src="$filters.getLinkUrl(props.info.coverUrl + '?imageView2/3/w/1000/format/webp')"
        alt=""
        @click="viewImg(props.info.coverUrl)"
      />
      <!-- 缩略图 -->
      <!-- store.isMobileType -->
      <!-- <div
        class="doot-box"
        :class="{ 'doot-anim': props.info.images?.length <= 4, 'doot-box-wap': store.isMobileType }"
        v-if="props.info.images?.length > 1"
        @mousewheel="handlWheel"
        ref="doot"
      >
        <div class="dot-content" v-for="(item, index) in props.info.images" :key="index">
          <div
            @click="current = index"
            class="doot-item"
            :class="{ 'doot-item-active': current === index, 'item-mg': index === 0 }"
          >
            <div class="shadown">
              <span v-if="item.type == -1">首页</span>
              <span v-else-if="item.type == 1">正视图</span>
              <span v-else-if="item.type == 2">俯视图</span>
              <span v-else-if="item.type == 3">侧视图</span>
              <span v-else-if="item.type == 4">全景图</span>
              <span v-else-if="item.type == 5">局部图</span>
              <span v-else-if="item.type == 6">底部图</span>
              <span v-else>未设置</span>
            </div>
            <img :src="$filters.getLinkUrl(item.data + '?imageView2/1/w/58/h/58/format/webp')" alt="" />
          </div>
        </div>
      </div> -->
      <!-- 3D标签 -->
      <div class="tag" @click="open3DUrl()" v-if="info.externalUrl">
        <img :src="publicUrls + 'free/style13/3DTag.png'" alt="" />
      </div>
    </div>
    <!-- 右侧描述 -->
    <div class="exhibhts-desc">
      <div class="exhibits-parameter">
        <div class="hint">基本信息</div>
        <div class="parameter-item">
          <div class="parameter-key">展品类型</div>

          <div class="parameter-name overflow">
            {{ props.info.typeValue || '--' }}
          </div>
        </div>

        <div class="parameter-item">
          <div class="parameter-key">展品来源</div>

          <div class="parameter-name overflow">
            {{ props.info.specificSources || '--' }}
          </div>
        </div>

        <div class="parameter-item">
          <div class="parameter-key">所属年代</div>

          <div class="parameter-name overflow">
            {{ props.info.concreteTimes ? props.info.concreteTimes : props.info.ageValue || '-' }}
          </div>
        </div>

        <div class="parameter-item">
          <div class="parameter-key">收藏单位</div>

          <div class="parameter-name overflow">{{ props.info.location ? props.info.location : info.companyName }}</div>
        </div>

        <div class="parameter-item">
          <div class="parameter-key">展品质地</div>

          <div class="parameter-name overflow">
            {{ props.info.texture || '--' }}
          </div>
        </div>
        <div class="parameter-item">
          <div class="parameter-key">展品级别</div>

          <div class="parameter-name">
            <span class="item-title2" v-if="props.info.levelValue == '一级展品'"> 一级展品 </span>
            <span class="item-title2" v-else-if="props.info.levelValue == '二级展品'"> 二级展品 </span>
            <span class="item-title2" v-else-if="props.info.levelValue == '三级展品'"> 三级展品 </span>
            <span class="item-title2" v-else>{{ props.info.levelValue || '--' }}</span>
          </div>
        </div>
        <div class="parameter-item">
          <div class="parameter-key">展品尺寸</div>

          <div class="parameter-name">
            {{ props.info.size || '--' }}
          </div>
        </div>
        <div class="parameter-item">
          <div class="parameter-key">展品图片</div>

          <div class="doot-box">
            <div class="dot-content" v-for="(item, index) in props.info.images" :key="index">
              <div
                @click="current = index"
                class="doot-item"
                :class="{ 'doot-item-active': current === index, 'item-mg': index === 0 }"
              >
                <div class="shadown">
                  <span v-if="item.type == -1">主视图</span>
                  <span v-else-if="item.type == 1">正视图</span>
                  <span v-else-if="item.type == 2">俯视图</span>
                  <span v-else-if="item.type == 3">侧视图</span>
                  <span v-else-if="item.type == 4">全景图</span>
                  <span v-else-if="item.type == 5">局部图</span>
                  <span v-else-if="item.type == 6">底部图</span>
                  <span v-else>未设置</span>
                </div>
                <img :src="$filters.getLinkUrl(item.data + '?imageView2/1/w/160/h/160/format/webp')" alt="" />
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="btn" v-if="info.openStatus === 1 && !store.isMobileType">
        <!-- 收藏展品 -->
        <!-- <t-popup
          v-if="info.openStatus === 1 && !store.isMobileType"
          attach="#template3-box"
          overlayClassName="popup"
          content="将此展品添加到我的关注"
          placement="top"
          destroyOnClose
        > -->
        <t-tooltip content="将此展品添加到我的关注" v-if="info.openStatus === 1 && !store.isMobileType">
          <div class="add-btn1 myPostattention" @click="postattention" v-if="info.openStatus === 1">
            <p v-if="!info.isFollow" class="iconfonts">&#xe6aa;</p>
            <p v-else class="iconfonts" style="color: #ffd058">&#xe6a9;</p>
            <!-- <div>{{ info.followTotal }}</div> -->
            <p>收藏展品</p>
          </div>
        </t-tooltip>
        <!-- </t-popup> -->

        <!-- 添加到展览 -->
        <!-- <t-popup
          v-if="info.openStatus === 1 && !store.isMobileType"
          attach="#template3-box"
          overlayClassName="popup"
          content="将此展品添加到我的展览"
          placement="top"
          destroyOnClose
        > -->
        <t-tooltip content="将此展品添加到我的展览" v-if="info.openStatus === 1 && !store.isMobileType">
          <div @click="addId" class="add-exhibition">
            <span class="iconfonts">&#xe6a7;</span>
            <span>添加至展览</span>
          </div>
        </t-tooltip>
      </div>
    </div>
    <!-- 添加展览弹窗 -->

    <!-- 是否登录 -->
    <messageModel
      submitText="前往"
      title="提示"
      :visible="visibleMessage"
      problem="您暂未登录"
      message="是否前往登录？"
      @closeClick="closeClick"
      @submitClick="pathSubmitClick"
      style="z-index: 999"
    />
  </div>
</template>

<script lang="ts">
export default defineComponent({
  name: 'exhibitsTop',
});
</script> 
  
<script setup lang="ts">
// @ts-nocheck
import { defineComponent, ref, computed, watch } from 'vue';
import { projectLists } from '@/api/project/project';
import { MessagePlugin } from 'tdesign-vue-next';
import { getHeardToken } from '@/api/utils';
import { addExhibits } from '@/api/desgin/desgin';
import { publicUrls } from '@/utils/minxin';
import { followSet } from '@/api/interact/interact';
import { useProjectStore } from '@/store';
import { ElMessage, ElMessageBox } from 'element-plus';
import type { Action } from 'element-plus';

const visibleMessage = ref(false);
const selectInitList = ref();
const projectId = ref(null);
const current = ref(0);
const store = useProjectStore();
const loading = ref(false);
const doot = ref(null);
const visibleStep = ref(false);
const Scrollheights = ref();

let viewportHeight = window.innerHeight;
Scrollheights.value = viewportHeight * 0.5688;
const getScrollHeight = computed(() => {
  let rootNode = document.documentElement;

  // 获取计算后的样式
  let computedStyle = window.getComputedStyle(rootNode);

  // 读取字体大小（注意这里返回的可能是一个包含单位的字符串，如"16px"）
  let fontSize = computedStyle.fontSize;

  // 如果你需要一个数字值（不带单位）进行计算，你可能需要解析这个字符串
  // 例如，使用正则表达式或split()方法去除单位，并将结果转换为数字
  let fontSizeNumber = parseFloat(fontSize.replace(/[^0-9.-]/g, ''));
  let heights = (fontSizeNumber / 144) * 512;
  return heights + 'px';
});
const props = defineProps({
  info: {
    type: Object,
  },
});

const emits = defineEmits(['viewImg', 'addExId']);

const viewImg = (i: any) => {
  emits('viewImg', i, current.value);
};

// 添加关注事件
const postattention = async () => {
  let token = getHeardToken();
  if (!token) {
    store.loginModeShow = true;

    return;
  } else {
    try {
      let { data } = await followSet({ refType: 4, refId: props.info.id });
      props.info.isFollow = data;
      if (props.info.isFollow) {
        props.info.followTotal = props.info.followTotal + 1;
        MessagePlugin.success('关注成功');
      } else {
        props.info.followTotal = props.info.followTotal === 0 ? 0 : props.info.followTotal - 1;
        MessagePlugin.warning('取消关注');
      }
    } catch {}
  }
};

//获取账号项目
const selectInit = async () => {
  try {
    let res = await projectLists(props.info.id);
    if (res.data.length > 0) {
      selectInitList.value = res.data;
      visibleStep.value = true;
      console.log(selectInitList.value);
    } else MessagePlugin.warning('暂无可添加的展览');
  } catch (err) {
    console.log(err);
  }
};

// 添加到展览
const addId = () => {
  let token = getHeardToken();
  if (!token) {
    // ElMessageBox.alert('是否前往登录？', '您暂未登录', {
    //   confirmButtonText: '确定',
    //   callback: (action: Action) => {
    //     if (action === 'confirm') {
    //       pathSubmitClick();
    //     }
    //   },
    // });
    // visibleMessage.value = true;
    store.loginModeShow = true;
    return;
  }
  // selectInit();
  emits('addExId');
};

const closetables = (context?: any): void => {
  visibleStep.value = false;
};

//添加项目
const okStep = async () => {
  try {
    if (loading.value) {
      return;
    }
    if (projectId.value) {
      loading.value = true;
      let res = await addExhibits(projectId.value, props.info.id, [props.info.id]);
      if (res.succeeded) {
        MessagePlugin.success('添加成功');
      }

      loading.value = false;
      visibleStep.value = false;
      projectId.value = null;
    } else {
      MessagePlugin.success('请选择展览');
      return;
    }
  } catch {
    loading.value = false;
  }
};

//取消
const closeClick = () => {
  visibleMessage.value = false;
};
//确认登录
const pathSubmitClick = () => {
  visibleMessage.value = false;
  let url = window.location.href;
  let redirectUrl = 'http://wz.wuzhan.art/#/login?redirect=' + url;
  window.location.href = redirectUrl;
};

const open3DUrl = () => {
  if (!props.info.externalUrl) return;
  window.open(props.info.externalUrl);
};

// 鼠标横向滚动事件
const handlWheel = (event: any) => {
  const delta = event.wheelDelta || -event.detail;
  doot.value.scrollLeft -= delta;
  event.preventDefault();
};

watch(
  () => props.info,
  () => {
    current.value = 0;
  },
);
</script> 

<style scoped lang="less">
.exhibit-top {
  width: 100%;
  flex-shrink: 0;
  display: flex;
  overflow: hidden;
  min-height: 490px;
  // max-height: 490px;
  .ex-img {
    width: 48%;
    // height: 100%;
    height: 490px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
    cursor: pointer;
    display: flex;
    justify-content: center;
    overflow: hidden;
    .cover {
      width: 100%;
      height: 100%;
      object-fit: contain;
      overflow: hidden;
    }
    .tag {
      width: 58px;
      height: 24px;
      position: absolute;
      top: 16px;
      right: 20px;
      cursor: pointer;
      img {
        width: 100%;
        height: 100%;
        object-fit: contain;
      }
    }
  }
  .exhibhts-desc {
    // width: 100%;
    width: calc(100% - 48%);
    // min-height: 100%;
    // max-height: 490px;
    margin-left: 50px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;

    .exhibits-parameter {
      width: 100%;
      display: flex;
      flex-direction: column;
      .hint {
        font-family: 'SourceHanSerifCN-Bold';
        font-size: 20px;
        color: #333333;
        line-height: 30px;
        text-align: left;
      }
      .parameter-item {
        margin-top: 16px;
        line-height: 24px;
        display: flex;
        .parameter-key {
          color: rgba(0, 0, 0, 0.38);
          font-size: 16px;
          margin-right: 20px;
          font-family: 'PingFang';
          flex-shrink: 0;
          min-width: 56px;
        }
        .parameter-name {
          flex: 1;
          font-family: 'PingFang-Bold';
          font-size: 16px;
          color: rgba(0, 0, 0, 0.8);
          span {
            font-family: 'PingFang-Bold' !important;
          }
        }
        .doot-anim {
          &:hover {
            justify-content: center !important;
          }
        }

        .doot-box {
          display: flex;
          flex-wrap: wrap;
          justify-content: start;
          width: 100%;
          padding-top: 6px;
        }
        .doot-item {
          transition: all 0.3s;
          cursor: pointer;
          width: 68px;
          height: 68px;
          margin-right: 2px;
          margin-bottom: 6px;
          position: relative;
          padding: 3px;
          &:hover {
            .shadown {
              opacity: 1;
            }
          }
          .shadown {
            width: 54px;
            height: 26px;
            opacity: 0;
            background: rgba(0, 0, 0, 0.4);
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            z-index: 1;
            border-radius: 2px;
            transition: all 0.3s;
            display: flex;
            justify-content: center;
            align-items: center;
            span {
              font-size: 14px;
              color: #fff;
            }
          }
          img {
            width: 100%;
            height: 100%;
          }
        }
        .doot-item-active {
          border: 1px solid #c40000;
        }
        .item-mg {
          margin-left: 0;
        }
      }
    }

    .btn {
      width: 100%;
      height: 48px;
      display: flex;
      margin-top: 40px;
      flex-shrink: 0;
      .myPostattention {
        min-width: 34px;
        height: 100%;
        margin-right: 30px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        align-content: center;
        flex-shrink: 0;
        color: rgba(51, 51, 51, 1);
        cursor: pointer;
        .iconfonts {
          height: 18px;
          font-size: 18px;
          margin-bottom: 4px;
          line-height: 20px;
          flex-shrink: 0;
        }
        p {
          width: 100%;
          text-align: center;
        }
        p:last-child {
          font-family: 'PingFang SC';
          font-size: 16px;
          line-height: 24px;
          text-align: center;
        }
      }
      .add-exhibition {
        width: 100%;
        height: 100%;
        border-radius: 4px;
        background: url(https://static.jiyi.show/free/style13/addExhibitionBg.png) no-repeat center/100% 100%;
        color: #fff;
        font-family: 'PingFang SC';
        font-size: 16px;
        line-height: 56px;
        cursor: pointer;
        display: flex;
        justify-content: center;
        align-items: center;

        .iconfonts {
          margin-right: 6px;
          font-size: 24px;
        }
      }
    }
  }
}
:deep(.t-dialog__body) {
  all: unset !important;
}
:deep(.t-dialog__header) {
  height: unset !important;
  all: unset !important;
  display: flex !important;
  margin-bottom: 15px !important;
}
:deep(.t-dialog__footer) {
  height: auto !important;
  all: unset !important;
  border: inherit !important;
  display: flex !important;
  justify-content: flex-end !important;
  margin-top: 15px !important;
}
:deep(.t-dialog) {
  background: #fff !important;
  padding: 20px !important;
  border-radius: 4px;
}
</style>
